package kr.hkit.powerjava.coffee.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Scanner;

import kr.hkit.powerjava.coffee.dao.DaoInterface;
import kr.hkit.powerjava.coffee.db.DbUtil;


public abstract class AbsService<T> {

	protected DaoInterface<T> dao;
	protected Scanner sc;
	protected Connection connection;

	public AbsService(Scanner sc, Connection connection) {
		this.sc = sc;
		this.connection = connection;
		//prnMenu();
	}

	private void close() {
		DbUtil.close(connection);
	}

	public abstract T inputItemInfo();
	public abstract void prnSubMenu(int sort);

	public void prnMenu(int res, int sort) {
		T item = null;

		do {
			System.out.print("1. 입력\n2. 리스트보기\n3. 종료\n");
			res = sc.nextInt();
			try {
				switch (res) {

				case 1:// 학생정보입력
					item = inputItemInfo();
					dao.insertItem(item);
					break;

				case 2:
					prnSubMenu(sort);
					break;

				default:
					res = 3;
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();

			}
		} while (res <= 2);
	}

}
